﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true"
    CodeBehind="Permission.aspx.cs" Inherits="SapB1WebPOS.Permission" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PopupContent" runat="server">
    <script type="text/javascript">
        var grid;
        var oUser = {};
        $(document).ready(function () {
            grid = $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "Permission.aspx/GetAllOnlineUser",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json"
                        },
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    pageSize: 1000,
                    type: "odata",
                    schema: {
                        data: function (response) {
                            if (response.d != null) {
                                var data = response.d;
                                return JSON.parse(data);
                            }
                        },
                        total: function (response) {
                            return JSON.parse(response.d).length;
                        },
                        model: {
                            id: "Code",
                            fields: {
                                Code: { type: "string" },
                                Name: { type: "string" },
                                U_PurchaseRequest: { type: "string" },
                                U_PurchaseOrder: { type: "string" },
                                U_SalesQuotation: { type: "string" },
                                U_SalesOrder: { type: "string" },
                                U_GRPO: { type: "string" },
                                U_WebPOS: { type: "string" }
                            }
                        }
                    }
                },
                height: 430,
                selectable: "row",
                batch: true,
                toolbar: [{ template:
                            '<a class="k-button" href="\\#" ><img src="images/multy-user.png" id="screen" title="User List" width="20px" height="20px" style="margin-right:3px;"/>User List </a>'
                }],
                columns: [
                { command: ["edit"], title: "Action", width: "160px" },
                { field: "Code", title: "User Name", width: 130 },
                { field: "Name", title: "Description" },
                { field: "U_PurchaseRequest", title: "Purchase Request" },
                { field: "U_PurchaseOrder", title: "Purchase Order" },
                { field: "U_SalesQuotation", title: "Sales Quotation" },
                { field: "U_SalesOrder", title: "Sales Order" },
                { field: "U_GRPO", title: "GRPO" },
                { field: "U_WebPOS", title: "POS" }
                            ],
                editable: {
                    mode: "inline"
                },
                edit: function (e) {
                    $("#lblErrorMsg").text('');
                    $('[name="Code"]').attr("disabled", true);
                    $('[name="Name"]').attr("disabled", true);
                },
                cancel: function (e) {
                },
                save: function (e) {
                    $("#lblErrorMsg").text('');
                    var listTextBox = $("input:text");
                    for (var i = 0; i < listTextBox.length; i++) {
                        var name = listTextBox[i].name;
                        if (name.length > 0) {
                            oUser[name] = $("[name=" + name + "]").val();
                        }
                    }
                    //Update or Insert Item
                    $.ajax({
                        type: "POST",
                        url: "Permission.aspx/UpdatePermission",
                        data: JSON.stringify({
                            oUser: JSON.stringify(oUser)
                        }),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if (data.d != "SUCCESS") {
                                $("#lblErrorMsg").text(data.d);
                            }
                            else {
                                $("#lblErrorMsg").css('color', 'blue');
                                $("#lblErrorMsg").text("Operation complete successful!");
                                grid.dataSource.read();
                            }
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            if (jqXHR.status == 500) {
                                alert('Internal error: ' + jqXHR.responseText);
                            } else {
                                alert('Unexpected error.' + jqXHR.responseText);
                            }
                        }
                    });
                }
            }).data("kendoGrid");
        });
    </script>
    <div id="grid">
    </div>
      <span id="lblErrorMsg" style="color: Red; font-size: 13pt; margin-left:2px;"></span>
</asp:Content>
